/*
 * @Author: Sam
 * @Date: 2025-04-29 10:20:23
 * @LastEditTime: 2025-04-30 14:40:05
 * @LastEditors: Sam
 */
import { ref } from "vue";
import { ENVConfig } from "../configs/ENVConfig";


/**应用token */
export const useApp = ()=>{

	const token = ref('');

	//应用APP ID
    const APP_ID = ENVConfig.app.id;

    //应用APP SECRET
    const APP_SECRET = ENVConfig.app.secret;

    //请求方法
    const fetchJSON = async (path:string)=>{

        //基础路径
        const url = ENVConfig.API_BASE_URL+path;
        const response = await fetch(url);
        const jsonResult = await response.json();
        return jsonResult;
    }

	const getToken = async ()=>{
		const tokenPath = '/bim-api/application-center/getToken?appId='+APP_ID+'&appSecret='+APP_SECRET;
		const { result:{access_token} } = await fetchJSON(tokenPath);
		token.value = access_token;
	}
	return { getToken, token };
}